package com.gui.hospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gui.hospital.model.HospitalDepartment;
import com.gui.hospital.service.HospitalDepartmentService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:刘舒佳
 * Date:2024/8/23
 */
@RestController
@AllArgsConstructor
@RequestMapping("/hospitalDepartment")
@CrossOrigin
public class HospitalDepartmentController {

    private final HospitalDepartmentService hospitalDepartmentService;
    /**
     * 查询所有科室
     */
    @GetMapping
    public List<HospitalDepartment> getAllDepartment(){
        return hospitalDepartmentService.list();
    }
    /**
     * 根据科室名称查询科室
     */
    @GetMapping("findByName")
    public List<HospitalDepartment> getDepartmentByName(@RequestParam(value = "name",required = false) String name){
        return hospitalDepartmentService.getDepartmentByName(name);
    }
    /**
     * 根据上级id查询科室
     */
    @GetMapping("findByPid")
    public List<HospitalDepartment> getDepartmentByPid(@RequestParam(value = "pid",required = false) Integer pid){
        return hospitalDepartmentService.getDepartmentByPid(pid);
    }

    /**
     * 添加科室
     * @param hospitalDepartment
     * @return
     */
    @PostMapping
    public boolean save(@RequestBody HospitalDepartment hospitalDepartment){
        return hospitalDepartmentService.save(hospitalDepartment);
    }

    /**
     * 根据id删除科室
     * @param id
     * @return
     */
    @DeleteMapping
    public boolean removeById(@RequestParam(value = "id") Integer id){
        return hospitalDepartmentService.removeById(id);
    }

    /**
     * 修改科室
     * @param hospitalDepartment
     * @return
     */
    @PutMapping
    public boolean updateById(@RequestBody HospitalDepartment hospitalDepartment){
        return hospitalDepartmentService.updateById(hospitalDepartment);
    }

    /**
     * 分页查询
     */
    @GetMapping("getPageList/{page}/{size}")
    public Page<HospitalDepartment> pageList(@PathVariable("page") Integer page, @PathVariable("size") Integer size,@RequestBody HospitalDepartment hospitalDepartment){
        return hospitalDepartmentService.pageList(page,size,hospitalDepartment,hospitalDepartment);

    }
}
